﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Data;
using System.Data.SqlClient;

/// <summary>
/// Summary description for GiftDAL
/// </summary>
public class GiftDAL
{
    DataAccess acc = new DataAccess();
    public GiftDAL()
    {
        //
        // TODO: Add constructor logic here
        //
    }

    public DataTable getGiftByCID(int id)
    {
        SqlParameter[] paraList = new SqlParameter[1];
        paraList[0] = new SqlParameter("@CG_ID", SqlDbType.Int);
        paraList[0].Value = id;
        return acc.executeSelect("getGiftByCID", paraList);
    }

    public DataTable getGiftByID(string id)
    {
        SqlParameter[] paraList = new SqlParameter[1];
        paraList[0] = new SqlParameter("@G_ID", SqlDbType.NVarChar, 50);
        paraList[0].Value = id;
        return acc.executeSelect("getGiftByID", paraList);
    }

    internal bool insertGift(string id, string name, float price, string details, string image, int cid)
    {
        SqlParameter[] paraList = new SqlParameter[6];
        paraList[0] = new SqlParameter("@G_ID", SqlDbType.NVarChar, 50);
        paraList[0].Value = id;
        paraList[1] = new SqlParameter("@G_Name", SqlDbType.NVarChar, 200);
        paraList[1].Value = name;
        paraList[2] = new SqlParameter("@G_Price", SqlDbType.Float);
        paraList[2].Value = price;
        paraList[3] = new SqlParameter("@G_Details", SqlDbType.NVarChar, 4000);
        paraList[3].Value = details;
        paraList[4] = new SqlParameter("@G_Image", SqlDbType.NVarChar, 4000);
        paraList[4].Value = image;
        paraList[5] = new SqlParameter("@CG_ID", SqlDbType.Int);
        paraList[5].Value = cid;
        int check = acc.executeModifier("insertGift", paraList);
        if (check > 0)
        {
            return true;
        }
        else
        {
            return false;
        }
    }

    internal DataTable getAllGift()
    {
        return acc.executeSelect("getAllGift");
    }

    internal bool updateStatusGift(string id)
    {
        SqlParameter[] paraList = new SqlParameter[1];
        paraList[0] = new SqlParameter("G_ID", SqlDbType.NVarChar, 50);
        paraList[0].Value = id;
        int check = acc.executeModifier("updateStatusGift", paraList);
        if (check > 0)
        {
            return true;
        }
        else
        {
            return false;
        }
    }

    internal bool updateGift(string id, string name, float price, string details, string image, int cid)
    {
        SqlParameter[] paraList = new SqlParameter[6];
        paraList[0] = new SqlParameter("@G_ID", SqlDbType.NVarChar, 50);
        paraList[0].Value = id;
        paraList[1] = new SqlParameter("@G_Name", SqlDbType.NVarChar, 200);
        paraList[1].Value = name;
        paraList[2] = new SqlParameter("@G_Price", SqlDbType.Float);
        paraList[2].Value = price;
        paraList[3] = new SqlParameter("@G_Details", SqlDbType.NVarChar, 4000);
        paraList[3].Value = details;
        paraList[4] = new SqlParameter("@G_Image", SqlDbType.NVarChar, 4000);
        paraList[4].Value = image;
        paraList[5] = new SqlParameter("@CG_ID", SqlDbType.Int);
        paraList[5].Value = cid;
        int check = acc.executeModifier("updateGift", paraList);
        if (check > 0)
        {
            return true;
        }
        else
        {
            return false;
        }
    }
}